<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>充值</title>
	<link rel="stylesheet" href="../css/weui.min.css" />
	<link rel="stylesheet" href="../fonts/iconfont.css" />
	<link rel="stylesheet" href="css/style.css" />
	<script src="js/jquery-2.2.3.min.js"></script>
	<script src="js/weui.min.js"></script>
</head>

<body ontouchstart>
	<div class='weui-conetent'>
		<div class='weui-content-padded'>选择充值金额</div>
		<div class="cznumber">
			<ul class="clearlist clearfix">
				<li>
					<input type="radio" name="num" id="n50" value="50" checked><label for="n50">50元</label>
				</li>
				<li>
					<input type="radio" name="num" id="n100" value="100"><label for="n100">100元</label>
				</li>
				<li>
					<input type="radio" name="num" id="n200" value="200"><label for="n200">200元</label>
				</li>
				<li>
					<input type="radio" name="num" id="n500" value="500"><label for="n500">500元</label>
				</li>
				<li>
					<input type="radio" name="num" id="n1000" value="1000"><label for="n1000">1000元</label>
				</li>
			</ul>
		</div>

		<div class='weui-content-padded'>其他充值金额</div>

		<div class='weui-content-padded'>
			<div class='weui-cells'>
				<div class='weui-cell outline'>
					<div class='weui-cell__bd'>
						<input type='number' class="weui-input Input-amount writeMoney">
					</div>
				</div>
			</div>

		</div>

		<div class='weui-content-padded'>
			<div>实际到账：<span class="color-red moneys">&yen;50</span></div>
			<div class="mt20"><input type='button' class="weui-btn weui-btn_primary" id="submit" value="确认"></div>
		</div>

	</div>
</body>
<script src="../api.js"></script>
<script>
	window.onload = function () {
		//输入框初始值
		let actualAccount = '¥50'
		$('.writeMoney').attr('value', 50)

		//当选中的时候
		$("input[type=radio]").click(function () {
			let moneynum = this.value
			$('.moneys').html('¥' + moneynum)
			$('.writeMoney').attr('value', moneynum)
		})

		//当输入框获取焦点的时候
		$('.writeMoney').focus(function () {
			$('.writeMoney').attr('value', '')
			$("input[type=radio]").removeAttr("checked")
			$('.moneys').html('¥'+ $('.writeMoney').val())
			//当输入框发生键盘事件
			$(".writeMoney").keyup(function (event) {
				$('.moneys').html('¥' + event.target.value)

			})
			$("input[type=radio]").click(function () {
				let moneynum = this.value
				$('.moneys').html('¥' + moneynum)
				$('.writeMoney').attr('value', moneynum)
			})
		})
		
		$('.writeMoney').blur(function () {
			if ($('.writeMoney').val() != '') {
				$('.moneys').html('¥' + event.target.value)
				$("input[type=radio]").removeAttr("checked")
			}
		})

	}




	// let userinfo = JSON.parse(localStorage.getItem('wxUserInfo')).data
	// let customerID = userinfo.customer.customerID
	// let api = getApi()
	// $('#submit').click(function () {
	// 	let checkedMoney = $('.moneys').text()
	// 	let money = checkedMoney.split('¥');
	// 	let params = {
	// 		"trade_type": "1",
	// 		"orderno": "",
	// 		"customerID": "2",
	// 		"body": "test",
	// 		"total_fee": "0.01",
	// 		"product_id": "",
	// 		"total_fee_type": "1"
	// 	}

	// 	$.ajax({
	// 		type: "POST",
	// 		dataType: 'json',
	// 		async: false,
	// 		data: JSON.stringify(params),
	// 		contentType: "application/json;charset=UTF-8",
	// 		url: 'http://yyyy.wezoz.com/qiheGroupMeal/unifiedorder',
	// 		success: function (payParams) {
	// 			let appId = payParams.appId
	// 			let timeStamp = payParams.timeStamp
	// 			let nonceStr = payParams.nonceStr
	// 			let package = payParams.package
	// 			let signType = payParams.signType
	// 			let paySign = payParams.paySign
	// 			// console.log(appId,timeStamp,nonceStr,package,signType,paySign)
	// 			function onBridgeReady() {
	// 				WeixinJSBridge.invoke(
	// 					'getBrandWCPayRequest', {
	// 						"appId": appId,     //公众号名称，由商户传入     
	// 						"timeStamp": timeStamp,         //时间戳，自1970年以来的秒数     
	// 						"nonceStr": nonceStr, //随机串     
	// 						"package": package,
	// 						"signType": signType,         //微信签名方式：     
	// 						"paySign": paySign //微信签名 
	// 					},
	// 					function (res) {
	// 						if (res.err_msg == "get_brand_wcpay_request:ok") {
	// 							// 使用以上方式判断前端返回,微信团队郑重提示：
	// 							//res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
	// 						}
	// 					});
	// 			}
	// 			if (typeof WeixinJSBridge == "undefined") {
	// 				if (document.addEventListener) {
	// 					document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	// 				} else if (document.attachEvent) {
	// 					document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
	// 					document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	// 				}
	// 			} else {
	// 				onBridgeReady();
	// 			}
	// 		}
	// 	})

		// axios.post('http://yyyy.wezoz.com/qiheGroupMeal/unifiedorder', {
		// 	trade_type: '1',
		// 	orderno: '',
		// 	customerID: '2',
		// 	body: '',
		// 	total_fee: '0.01',
		// 	product_id: '',
		// 	total_fee_type: '1'
		// }).then(function(data){
		// 	console.log(data)
		// }).catch(function(err){
		// 	console.log(err)
		// })
	// })
</script>

</html>